import React, { Component } from 'react';
import { hashHistory } from 'react-router';
import { Grid, Toast } from 'antd-mobile';
import 'common/components/recommendItem.less';

class RecommendItem extends Component{

	gotoDetail = (el, index) => {
		if(el && el.id && el.id != ""){
			hashHistory.push("/bookDetail/"+el.id);
		}else{
			Toast.info("书籍不存在", 2);
		}
	}

	render(){
		const { recommendList } = this.props;

		return(
			<div>
				{
					recommendList && recommendList.length > 0 && recommendList.map((recommendItem, index) => {
						let bookList = [];
						recommendItem.recommend.map((recommend, index) => {
							let bookImage = recommend.book.cover;
							bookImage = bookImage.replace("http://statics.zhuishushenqi.com/agent/http://wap.cmread.com","");
							let bookinfo = {
								id: recommend.book._id,
								icon: bookImage,
								text: recommend.book.title
							}
							bookList.push(bookinfo);
						})

						return(
							<div key={index} className="recommend_item">
								<h1>{recommendItem.title}</h1>
								<div className="split_line"></div>
								<Grid activeStyle={false} columnNum={3} hasLine={false} data={bookList}
									onClick={(el, index) => this.gotoDetail(el, index)}/>
							</div>
						)
					})
				}
			</div>
			
		)
	}
}

export default RecommendItem;